package com.example.win.android_banduyujia.venuesactivity.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.StrictMode;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.RatingBar;
import android.widget.TextView;

import com.example.win.android_banduyujia.R;
import com.example.win.android_banduyujia.login.application.ILoginStatusChangedListener;
import com.example.win.android_banduyujia.login.application.LoginApplication;
import com.example.win.android_banduyujia.peopleactivity.activity.activity.openactivity.NotificationActivity;
import com.example.win.android_banduyujia.peopleactivity.activity.activity.openactivity.SettingsActivity;
import com.example.win.android_banduyujia.ui.view.CircleImageView;
import com.example.win.android_banduyujia.venuesactivity.activity.openactivity.VenuesCourseActivity;
import com.example.win.android_banduyujia.venuesactivity.activity.openactivity.VenuesMyOrderActivity;
import com.example.win.android_banduyujia.venuesactivity.activity.openactivity.VenuesMyProjectActivity;
import com.example.win.android_banduyujia.venuesactivity.activity.openactivity.VenuesTodayActivity;
import com.example.win.android_banduyujia.venuesactivity.activity.payactivity.VenuesMyincomeActivity;

/**
 * Created by Win on 2015/9/12.
 */
public class GroupActivity extends Activity implements View.OnClickListener, ILoginStatusChangedListener {
    public static final String TAG = GroupActivity.class.getSimpleName();

    private static  final  String  CircleImageView = null;
    private CircleImageView mHeaderImageView;

    private ImageView mVenuesNotifition,mVenuesSettings;  // 通知消息，设置
    private TextView  mTvtVenuesName,mTvtVenuesNumber; // 名字,进度条数字
    private ImageView mIgeVenuesIcon; // 图标
    private RatingBar mRatVenuesBar; // 星星进度条
    private Button    mBtnVenuesData; // 完善资料
    private TextView  mTvtVenuesCourse, mTvtVenuesToday; // 已发课数， 今日课程
    private Button    mBtnVenuesCourse, mBtnVenuesToday;
    private ImageView mIgeVenuesOrder, mIgeVenuesIncome, mIgeVenuesCourse; // 今日订单，我的收入，我的课程
    private TextView  mTvtVenuesOrder, mTvtVenuesIncome, mTvtVenuesMeCourse;
    private TextView  mTvtVenuesTar, mTvtVenuesComtar; // 发布私教， 企业课

    private String    mAccessToken;
    private LoginApplication  mLoginAppLication;
    // private LoginInfEntity    mLoginInfo;
    private PopupWindow popupWindow;

    // 关于请求用户头像的变量
    private final int REFRESH_ICON = 1;
    private Bitmap bitmapIcon = null;
    // 刷新头像
    private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what){
                case REFRESH_ICON:
                    mHeaderImageView.setImageBitmap(bitmapIcon);
                    break;
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_venues_people);

        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork().penaltyLog().build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects().detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());

        InitViews();
         refreshViews();
         addLoginListener();
    }

    private void addLoginListener() {
        mLoginAppLication = LoginApplication.getInstance();
        mLoginAppLication.addLoginOrLogoutListener(this);
    }

    @Override
    public void isLoginOrLogout() {
        refreshViews();
    }

    private void refreshViews() {

    }

    private void InitViews() {
        mVenuesNotifition = (ImageView) findViewById(R.id.layout_page_image_view_venues_notification);
        mVenuesSettings = (ImageView) findViewById(R.id.layout_page_image_view_venues_settings);
        mHeaderImageView = (CircleImageView) findViewById(R.id.me_fragment_header_venues_view);
        mTvtVenuesName = (TextView) findViewById(R.id.me_fragment_text_venues_view);
        mIgeVenuesIcon = (ImageView) findViewById(R.id.me_fragemnt_image_venues_icon);
        mRatVenuesBar = (RatingBar) findViewById(R.id.rating_venues_bar);
        mTvtVenuesNumber = (TextView) findViewById(R.id.layout_people_text_view_venues_number);
        mBtnVenuesData = (Button) findViewById(R.id.me_fragment_btn_venues_data);

        mTvtVenuesToday = (TextView) findViewById(R.id.me_fragemnt_text_today_venues_course);
        mTvtVenuesCourse = (TextView) findViewById(R.id.me_fragemnt_text_today_course_venues_number);
        mBtnVenuesCourse = (Button) findViewById(R.id.me_fragemnt_btn_today_venues_number);
        mBtnVenuesToday = (Button) findViewById(R.id.me_fragemnt_button_today_venues_number);

        mIgeVenuesOrder = (ImageView) findViewById(R.id.me_fragemnt_image_venues_order);
        mIgeVenuesIncome = (ImageView) findViewById(R.id.me_fragemnt_image_venues_income);
        mIgeVenuesCourse = (ImageView) findViewById(R.id.me_fragemnt_image_venues_course);

        mTvtVenuesOrder = (TextView) findViewById(R.id.me_fragemnt_text_venues_order_my);
        mTvtVenuesIncome = (TextView) findViewById(R.id.me_fragemnt_text_venues_course_my);
        mTvtVenuesMeCourse = (TextView) findViewById(R.id.me_fragemnt_text_couser_venues_my);
        mTvtVenuesComtar = (TextView) findViewById(R.id.me_fragment_text_view_release_group_class);

        mVenuesNotifition.setOnClickListener(this);
        mVenuesSettings.setOnClickListener(this);
        mHeaderImageView.setOnClickListener(this);
        mBtnVenuesData.setOnClickListener(this);
        mTvtVenuesToday.setOnClickListener(this);
        mTvtVenuesCourse.setOnClickListener(this);
        mIgeVenuesOrder.setOnClickListener(this);
        mIgeVenuesIncome.setOnClickListener(this);
        mIgeVenuesCourse.setOnClickListener(this);
        mTvtVenuesComtar.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.layout_page_image_view_venues_notification: // 通知消息
                VenuesstartActivity();
                break;
            case R.id.layout_page_image_view_venues_settings: // 设置
                VenuesSetActivity();
                break;
            case R.id.me_fragment_header_venues_view: // 头像
                VenuesPhoneActivity();
                break;
            case R.id.me_fragment_btn_venues_data: // 完善资料
                VenuesDatoActivity();
                break;
            case R.id.me_fragemnt_text_today_course_venues_number: // 今日课程数
                VenuestodayActivity();
                break;
            case R.id.me_fragemnt_text_today_venues_course:   // 已发课程
                VenuescourseActivity();
                break;
            case R.id.me_fragemnt_image_venues_order: // 我的订单
                VenuesMyOrderActivity();
                break;
            case R.id.me_fragemnt_image_venues_income: // 我的收入
                VenuesMyIncomeActivity();
                break;
            case R.id.me_fragemnt_image_venues_course: // 我的课程
                VenuesMyProActivity();
                break;
            case R.id.me_fragment_text_view_release_group_class: // 发布团课
                VenuesTarActivity();
                break;
        }
    }

    private void VenuesstartActivity() {
        startActivity(new Intent(this, NotificationActivity.class));
    }

    private void VenuesSetActivity() {
        startActivity(new Intent(this, SettingsActivity.class));
    }

    private void VenuesPhoneActivity() {
        startActivity(new Intent(this, VenuesMateralActivity.class));
    }

    private void VenuesDatoActivity() {  // 完善资料
        startActivity(new Intent(this, VenuesMateralActivity.class));
    }

    private void VenuescourseActivity() {
        startActivity(new Intent(this, VenuesCourseActivity.class));
    }

    private void VenuestodayActivity() {
        startActivity(new Intent(this, VenuesTodayActivity.class));
    }

    private void VenuesMyOrderActivity() {
        startActivity(new Intent(this, VenuesMyOrderActivity.class));
    }

    private void VenuesMyIncomeActivity() {
        startActivity(new Intent(this, VenuesMyincomeActivity.class));
    }

    private void VenuesMyProActivity() {
        startActivity(new Intent(this, VenuesMyProjectActivity.class));
    }

    private void VenuesTarActivity() {  // 发布团课
        startActivity(new Intent(this, VenuesTarActivity.class));
    }
}
